"""
Adapted from Html5 Boilerplate.
"""
from minimarkup import P, Q

OUTDATED = Q.strong('outdated')
UPGRADE = Q.a('upgrade your browser' , href="http://browsehappy.com/")

class Html5(P):
    NOCLOSE = 'br', 'hr', 'img', 'link', 'meta'
    TAGS = 'a', 'body', 'br', 'button', 'div', 'h1', 'h2', 'h3', 'head', 'hr', 'html', 'img', 'link', 'meta', 'p', 'script', 'title', 'table', 'tr', 'th', 'td'

    def __init__(self, title, js=False):
        P.__init__(self, '<!DOCTYPE html>')
        self._js = js
        self.html(class_='no_js')

        self.head()
        self.meta (charset="utf-8")
        self.meta (http_equiv="X-UA-Compatible", content="IE=edge")
        self.title(title)
        self.meta(name="description", content="")
        self.meta(name="viewport", content="width=device-width, initial-scale=1")
        self.link(rel='shortcut icon', href='/static/img/favicon.ico')
        self.link(rel="stylesheet", href="/static/css/normalize.css")
        self.link(rel="stylesheet", href="/static/css/main.css")
        self.script(src="/static/js/vendor/modernizr-2.6.2.min.js").close()
        self.head.close()

        self.body()
        self += '<!--[if lt IE 8]>'
        self.p('You are using an %s browser.\n\t\tPlease %s to improve your experience.' % (OUTDATED, UPGRADE), class_="browsehappy")
        self += '<![endif]-->'

    def render(self):
        if self._js:
            self.script(src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js").close()
            self.script("window.jQuery || document.write('%s')" % r'<script src="/static/js/vendor/jquery-1.10.2.min.js"><\/script>')
            self.script(src="/static/js/plugins.js").close()
            self.script(src="/static/js/main.js").close()
        self.body.close()

        self.html.close()
        return self()
